package com.leetcode.partition13;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author rkc
 * @date 2022/8/14 9:25
 */
public class LC1282用户分组 {

    private static final int N = 510;
    private static Map<Integer, List<Integer>> map = new HashMap<>(N);
    private static int n;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int n = nextInt();
        int[] w = new int[n];
        for (int i = 0; i < n; i++) w[i] = nextInt();
        writer.println(groupThePeople(w));
        writer.flush();
    }

    public static List<List<Integer>> groupThePeople(int[] groupSizes) {
        n = groupSizes.length;
        List<List<Integer>> ans = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            List<Integer> ls = map.getOrDefault(groupSizes[i], new ArrayList<>());
            ls.add(i);
            if (ls.size() == groupSizes[i]) {
                ans.add(ls);
                map.remove(groupSizes[i]);
            } else {
                map.put(groupSizes[i], ls);
            }
        }
        for (Map.Entry<Integer, List<Integer>> entry : map.entrySet()) {
            ans.add(entry.getValue());
        }
        return ans;
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
